<template>
  <div class="content">
    <!-- 头部区域 -->
    <el-row>
      <div>
        <span>申请时间</span>
        <el-date-picker
          v-model="date"
          type="datetimerange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['12:00:00']"
        />
      </div>
      <div>
        <span>审核状态</span>
        <el-select v-model="query.status" style="width: calc(100% - 128px);" placeholder="请选择">
          <el-option v-for="(val, key, i) in options" :key="i" :label="val" :value="key" />
        </el-select>
      </div>
      <div>
        <el-button type="primary" plain class="filter" @click="getScreenList">筛选</el-button>
        <el-button type="primary" plain class="reset" circle @click="reload">
          <i class="el-icon-refresh-right" />
        </el-button>
      </div>
    </el-row>
    <!-- 表格区域 -->
    <el-table
      height="73.5vh"
      :data="entryList"
      style="width: 100%;margin:0;"
      :header-cell-style="{color:'black'}"
    >
      <el-table-column min-width="120px" prop="uid" label="入账编号" />
      <el-table-column label="入账金额">
        <template v-slot="scope">
          <el-tooltip class="item" effect="dark" :content="$capitalizationAmount( scope.row.amount)" placement="top-start">
            <span>￥{{ scope.row.amount }}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="content" label="入账备注">
        <template v-slot="scope">
          <span v-if="scope.row.content === null || scope.row.content===''">---</span>
          <tool v-else :content="scope.row.content" :wrap="false">
            {{ scope.row.content }}
          </tool>
        </template>
      </el-table-column>
      <el-table-column min-width="120px" prop="created_at" label="申请时间" />
      <el-table-column label="入账状态">
        <template v-slot="scope">
          <el-tag v-if="scope.row.status === 'PLATFORM_GIFT'" effect="dark">平台调整</el-tag>
          <el-tag v-else-if="scope.row.status ==='CHECK_PASS'" effect="dark">已入账</el-tag>
          <el-tag v-else-if="scope.row.status ==='CHECK_REJECT'" effect="dark" type="danger">已拒绝</el-tag>
          <el-tag v-else-if="scope.row.status ==='WITH_CHECK'" effect="dark" type="warning">待入账</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审批人" width="140">
        <template v-slot="scope">
          <span v-if="scope.row.check_user === null || scope.row.check_use ==='' ">---</span>
          <span v-else>
            <tool :content="scope.row.check_user" :wrap="false">
              {{ scope.row.check_user }}
            </tool>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="审批时间" min-width="120px">
        <template v-slot="scope">
          <span v-if="scope.row.check_datetime === null">---</span>
          <span v-else>{{ scope.row.check_datetime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
          <a class="check" @click="seeDetails(scope.row)">查看</a>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页区域 -->
    <div class="dingwei">
      <el-pagination
        :current-page="query.page"
        :page-sizes="$arrays.tableSize"
        :page-size="query.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <!-- 弹出对话框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <span style="display:block;margin-bottom:24px">{{ row.check_content }}</span>
      <span>{{ row.check_datetime }}--{{ row.check_user }}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getEntryList } from '@/api/capital'
import tool from '@/components/tool'
export default {
  name: 'Entry',
  components: { tool },
  data() {
    return {
      query: {
        limit: 20,
        page: 1,
        status: '',
        start_at: '',
        end_at: ''
      },
      value: '选项0',
      total: 0,
      date: '',
      dialogVisible: false,
      options: {
        '': '全部',
        WITH_CHECK: '待入账',
        CHECK_PASS: '已入账',
        CHECK_REJECT: '已拒绝'
      },
      entryList: [],
      // 筛选后
      newEntryList: [],
      // row
      row: {}
    }
  },
  created() {
    this.getEntryList()
  },
  methods: {
    handleSizeChange(newPageSize) {
      this.query.limit = newPageSize
      this.getEntryList()
    },
    handleCurrentChange(newPage) {
      this.query.page = newPage
      this.getEntryList()
    },
    getEntryList() {
      getEntryList(this.query).then((res) => {
        this.entryList = res.data.data.data

        this.total = res.data.data.total
      })
    },
    getScreenList() {
      if (this.date.length === 0) {
        this.getEntryList()
      } else {
        var star = new Date(this.date[0])
        var end = new Date(this.date[1])
        this.query.start_at =
          star.getFullYear() +
          '-' +
          (star.getMonth() + 1) +
          '-' +
          star.getDate() +
          ' ' +
          star.getHours() +
          ':' +
          star.getMinutes() +
          ':' +
          star.getSeconds()
        this.query.end_at =
          end.getFullYear() +
          '-' +
          (end.getMonth() + 1) +
          '-' +
          end.getDate() +
          ' ' +
          end.getHours() +
          ':' +
          end.getMinutes() +
          ':' +
          end.getSeconds()
        this.getEntryList()
      }
    },
    seeDetails(row) {
      switch (row.status) {
        case 'PLATFORM_GIFT':
          this.$message({
            showClose: true,
            duration: 3000,
            message: '该账目为平台调整，如需了解更多请联系专员'
          })
          break
        case 'WITH_CHECK':
          this.$message({
            showClose: true,
            duration: 3000,
            message: '您的入账申请正在审核中'
          })
          break
        case 'CHECK_PASS':
          this.$message({
            showClose: true,
            duration: 3000,
            message: '您的入账申请已通过，资金已入账',
            type: 'success'
          })
          break
        case 'CHECK_REJECT':
          this.dialogVisible = true
          this.row = row
          //
          break
      }
    },
    // 刷新当前页面
    reload() {
      this.query = {
        limit: 20,
        page: 1,
        status: '',
        start_at: '',
        end_at: ''
      }
      this.date = ''
      this.getEntryList()
    }
  }
}
</script>
<style lang="scss" scoped>
.content {
  padding: 24px;
}
.el-date-editor--datetimerange.el-input__inner {
  min-width: 325px;
  width: calc(100% - 128px);
}
.reset {
  width: 40px;
  margin: 0;
  margin-left: 20px;
}
.check {
  color: #4a9aff;
}
</style>
<style lang="scss" scoped>
.el-row {
  margin: 0;
  margin-bottom: 40px;
  min-width: 1366px;
  div {
    width: 33.3%;
    display: inline-block;
    span {
      font-size: 16px;
      font-weight: bold;
      margin-right: 24px;
    }
  }
}
</style>
<style lang="scss">
.el-range-editor--small .el-range-input {
  font-size: 12px;
}
.el-range-editor--medium .el-range-input {
  font-size: 12px;
}
.el-form-item__label {
  color: black;
}
.dingwei {
  // margin-top: 16px;
  position: fixed;
  bottom: 0;
  width: 100%;
  background-color: white;
  padding-bottom: 50px;
  padding-top: 40px;
}
</style>
